package easy;

/**
 * @author admin
 * 1281. 整数的各位积和之差
 * 解题思路：模拟法，%10得到每个位上的数字，/10来决定循环是否终止
 */
public class LeeCode1281 {

    public int subtractProductAndSum(int n) {

        int sum = 0;
        int mul = 1;
        int num;
        while (n > 0){
            num = n%10;
            n = n / 10;
            mul = mul*num;
            sum = sum+num;
        }
        return mul - sum;
    }

    public static void main(String[] args) {
        System.out.println(new LeeCode1281().subtractProductAndSum(234));
    }
}
